package cn.ld.module.system.dal.mapper.permission;

import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.module.system.dal.entity.permission.UserRoleEntity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface UserRoleMapper extends BaseMapperX<UserRoleEntity> {

    default List<UserRoleEntity> selectListByUserId(Long userId) {
        return selectList(UserRoleEntity::getUserId, userId);
    }

    default void deleteListByUserIdAndRoleIdIds(Long userId, Collection<Long> roleIds) {
        delete(new LambdaQueryWrapper<UserRoleEntity>()
                .eq(UserRoleEntity::getUserId, userId)
                .in(UserRoleEntity::getRoleId, roleIds));
    }

    default void deleteListByUserId(Long userId) {
        delete(new LambdaQueryWrapper<UserRoleEntity>().eq(UserRoleEntity::getUserId, userId));
    }

    default void deleteListByRoleId(Long roleId) {
        delete(new LambdaQueryWrapper<UserRoleEntity>().eq(UserRoleEntity::getRoleId, roleId));
    }

    default List<UserRoleEntity> selectListByRoleIds(Collection<Long> roleIds) {
        return selectList(UserRoleEntity::getRoleId, roleIds);
    }

}
